package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.entity.MqMonitorResult;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class MonitorNumberReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *TJ,2020916301,V4,MONITOR,173030,13912345678,status,050315,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFFFF#
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String phoneNumber=split[5];//被监听的手机号码
        String status = split[6];//监听结果 1-成功
        String deviceTime = split[7];//时分秒时间
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];//年月日
        String deviceStatus = split[16];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        MqMonitorResult mqMonitorResult = new MqMonitorResult();
        mqMonitorResult.setCommandNumber(commandNumber);
        mqMonitorResult.setDeviceDate(deviceDate);
        mqMonitorResult.setDeviceTime(deviceTime);
        mqMonitorResult.setImei(imei);
        mqMonitorResult.setDeviceStatus(deviceStatus);
        mqMonitorResult.setPhone(phoneNumber);
        mqMonitorResult.setResult(Integer.parseInt(status));
        mqMonitorResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().monitorResponse(mqMonitorResult);
        return imei;
    }
}
